package com.bluebench.bigul.service.resolver;

import java.util.ArrayList;
import java.util.List;

import com.bluebench.bigul.domain.Element.Parameter;
import com.bluebench.bigul.exception.GraphicInitializationException;

public class CollectionResolver extends DefaultExpressionResolver{

	public CollectionResolver() throws GraphicInitializationException {
		if(!IS_INITIALIZED){
			super.resolve();
		}
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public void resolve() throws GraphicInitializationException {
		
		List resolvedParameterList = new ArrayList();
		Parameter p = (Parameter)tag;
		Object value = p.getValue();
		
		if(value!=null && (value instanceof ArrayList)){
			ArrayList<Parameter> params = (ArrayList<Parameter>)value;
			for(Parameter param : params){
				param.setResolver(getInstance(PARAMETER_RESOLVER));
				param.resolve();
				Object val = param.getValue();
				resolvedParameterList.add(val);				
			}			
			
			if(!resolvedParameterList.isEmpty()){
				p.setValue(value);			
			}else{
				p.setValue(null);
			}
		}
		
		
	}
	
	
}
